﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebBanThuoc.DTO;
using WebBanThuoc.Function;

namespace WebBanThuoc.Function
{
    public class FuncAdmin
    {
        public static bool IsLogin(System.Web.SessionState.HttpSessionState session)
        {
            UserAdmin uAdmin = session["dataLoginAdmin"] as UserAdmin;
            if (uAdmin == null)
                return false;
            else
            {
                if (uAdmin.UserName != null && uAdmin.UserName.Trim() != "" && uAdmin.TimeLogin.Ticks == Convert.ToInt64(Encryption.Decrypt(uAdmin.Code)))
                    return true;
                else
                    return false;
            }
        }

        private static UserAdmin _getDataUserLoginCurrent(System.Web.SessionState.HttpSessionState session)
        {
            UserAdmin uAdmin = session["dataLoginAdmin"] as UserAdmin;
            return uAdmin;
        }

        public static UserAdmin getDataUserLoginCurrent(System.Web.SessionState.HttpSessionState session)
        {
            return _getDataUserLoginCurrent(session);
        }

        private static bool _removeDataUserLoginAdminCurrent(System.Web.SessionState.HttpSessionState session, string UserName, string code)
        {
            UserAdmin uAdmin = session["dataLoginAdmin"] as UserAdmin;
            if (uAdmin == null)
                return true;
            else
            {
                if (uAdmin.UserName == UserName && uAdmin.Code == code)
                {
                    session.Remove("dataLoginAdmin");
                    return true;
                }
                else
                    return false;
            }
        }

        public static bool removeDataUserLoginAdminCurrent(System.Web.SessionState.HttpSessionState session, string UserName, string code)
        {
            return _removeDataUserLoginAdminCurrent(session, UserName, code);
        }

        private static bool _createDataUserLoginAdminCurrent(System.Web.SessionState.HttpSessionState session, UserAdmin userAdmin)
        {
            session.Add("dataLoginAdmin", userAdmin);
            return true;
        }

        public static bool createDataUserLoginAdminCurrent(System.Web.SessionState.HttpSessionState session, UserAdmin userAdmin)
        {
            return _createDataUserLoginAdminCurrent(session, userAdmin);
        }
    }
}